using System;
using System.ComponentModel;
using System.ComponentModel.Design;

using System.Drawing;
using System.Drawing.Drawing2D;

namespace Camalon.Drawing
{
    /// <summary>
    /// This is the base class of all designable components in the Visual Drawing.Net.
    /// </summary>
	[ToolboxItem( false )]
//	[ToolboxItemFilter("Camalon.Drawing.Shape", ToolboxItemFilterType.Require)]
    public abstract class ContainerComponentBase : Component, ICloneable
	{
		[Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
		public EventHandler InternalChanged	= null;//Changed from internal

		#region Dispose/Clone

        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.ComponentModel.Component"/> and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
		protected override void Dispose(bool disposing)
		{
			Delegate.RemoveAll( InternalChanged,InternalChanged );
			this.InternalChanged = null;
			base.Dispose (disposing);
		}


        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
		public virtual object Clone()
		{
			ContainerComponentBase cb= this.MemberwiseClone() as ContainerComponentBase;
			Delegate.RemoveAll( cb.InternalChanged,cb.InternalChanged );
			cb.InternalChanged = null;
			return cb;
		}


		#endregion Dispose/Clone

		#region Event Handler
        /// <summary>
        /// Raises the <c>InternalChanged</c> event/>
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected virtual void OnInternalChanged(object sender, EventArgs e)
		{ 
			if( InternalChanged != null) InternalChanged( this,e);
		}

        /// <summary>
        /// Invokes the internal changed.
        /// </summary>
		internal void InvokeInternalChanged()
		{
			this.OnInternalChanged( this, new EventArgs());
		}

		#endregion Event Handler

	}
}
